# -*- coding: utf-8 -*-
# Author: xiantingDeng
# File: execute.py
# Time: 9:48


from bin.common.element import ElementActions
from crm.page.user_action_page.handler import LoginPage
from crm.page.user_action_page.handler import LogOutPage

logins = LoginPage()
logouts = LogOutPage()


def login(action: ElementActions, username, passwd):
    '''
    让APP处于登录装，已登录时则不登录，登录后处于用户中心页
    :param action: driver
    :param username: 账号
    :param passwd: 密码
    :return:  TRUE  FALSE
    '''
    if action.is_element_exist(logins.登录注册按钮):
        action.click_element(logins.登录注册按钮)
        action.click_element(logins.切换账号密码登录按钮)
        action.input_value(logins.账号输入框,username,clear_first=True)
        action.input_value(logins.密码输入框,passwd,clear_first=True)
        action.check_chckbox(logins.同意用户协议按钮)
        action.click_element(logins.登录按钮)


def logout(action: ElementActions):
    '''
    退出登录
    :param action:
    :return:
    '''
    action.click_element(logouts.设置按钮)
    action.click_element(logouts.退出账号按钮)
    action.click_element(logouts.确认按钮)


